﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AdImgPlaySort.aspx.cs" Inherits="AdImgPlaySort" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        body
        {
            font-size: 13px;
            font-family: "Trebuchet MS" , "Helvetica" , "Arial" , "Verdana" , "sans-serif";
        }
        #sortable
        {
            width: 510px;
            float: left;
        }
        #sortable div
        {
            margin-bottom: 5px;
        }
        #sortright
        {
            width: 40%;
            float: right;
        }
        .ui-state-default
        {
            border: 1px solid #d3d3d3;
            background: #e6e6e6 url(ui-bg_glass_75_e6e6e6_1x400.png) 50% 50% repeat-x;
            font-weight: normal;
            color: #555555;
            outline: none;
            text-align: left;
            padding: 4px;
        }
        .ui-state-default span
        {
            padding: 0px 20px 0px 0px;
        }
    </style>
    <link href="../../Content/css/ui-lightness/jquery-ui-1.8.16.custom.css" rel="stylesheet"
        type="text/css" />
    <script src="../../Content/js/jquery-1.6.2.min.js" type="text/javascript"></script>
    <link href="../../Content/Style.css" rel="stylesheet" type="text/css" />
    <script src="../../Content/js/ui.core.js" type="text/javascript"></script>
    <script src="../../Content/js/ui.sortable.js" type="text/javascript"></script>
    <script src="../../Content/js/jquery-ui-1.8.16.custom.min.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
        $(document).ready(function () {
            getSortPlayList($("#drp_moviePlayList").val());
            $("#drp_moviePlayList").change(function () {
                var id = $(this).val();
                getSortPlayList(id);
            })
            $("#btn_save").click(
				function () {
				    var a = $("#sortable div span:odd");
				    var pids = ""; //播放顺序集合
				    var mids = ""; //影片ID集合
				    var id = $("#drp_moviePlayList").val();
				    a.each(function (i) {
				        pids += (i + 1) + ",";
				        mids += this.id.replace("item", "") + ",";
				    });
				    if (pids == "" || mids == "") {
				        return;
				    }
				    $.post("../../ProgressHandler/AdImg/SaveSortPlayList.ashx", { id: id, pids: pids, mids: mids }, function (data) {
				        if (data == "1") {
				            alert("保存成功！");
				        }
				        else { alert("保存失败！"); }
				    });
				}
		        );
            $("#btn_add").click(function () {
                var horizontalPadding = 30;
                var verticalPadding = 30;
                var id = $("#drp_moviePlayList").val();
                $("<iframe id='externalSite' src='AdImgPlaySortAdd.aspx?id=" + id + "' scrolling='no' />").dialog({
                    title: "添加广告至列表",
                    autoOpen: true,
                    width: 650,
                    height: 400,
                    modal: true,
                    resizable: true,
                    autoResize: true,
                    beforeclose: function () { window.location.href = "AdImgPlaySort.aspx?id=" + id; },
                    overlay: {
                        opacity: 0.5,
                        background: "black"
                    }
                }).width(650 - horizontalPadding).height(400 - verticalPadding);
            })
        })
        // 
        function getSortPlayList(Id) {
            var cc = "";
            var timesmap = Date.parse(new Date());
            $.getJSON("../../ProgressHandler/AdImg/GetSortPlayList.ashx?id=" + Id + "&time=" + timesmap, function (data) {
                $.each(data, function (i, n) {
                    cc += "<div class='ui-state-default'>" +
                    "<span id='item" + n.ID + "' name='Item " + n.ID + "'>" + n.Adname + "&nbsp;&nbsp;&nbsp;" + n.Bigimgname + "&nbsp;&nbsp;&nbsp;" + n.CreateDate + "<a style='padding:0px 0px 0px 100px' href='javascript:void(0)' onclick='del(" + n.ID + ")'>删除</a></span>" +
                    "</div>";
                })
                $("#sortable").html(cc);
                $("#sortable").sortable({ items: 'div' });
                $("#sortable").sortable({ cancel: 'b' });

            });
        }
        //del
        function del(mid) {
            var id = $("#drp_moviePlayList").val();
            $.getJSON("../../ProgressHandler/AdImg/DelSortPlayList.ashx?id=" + id + "&mid=" + mid, function (data) {
                if (data == "1") {
                    getSortPlayList(id);
                }
                else { alert("删除失败！"); }

            });

        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
                <td height="30">
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td width="15" height="30">
                                <img src="/Content/images/tab/tab_03.gif" width="15" height="30" />
                            </td>
                            <td width="1101" background="/Content/images/tab/tab_05.gif">
                                <img src="/Content/images/tab/311.gif" width="16" height="16" />
                                <span class="STYLE4">影片管理</span>
                            </td>
                            <td width="281" background="/Content/images/tab/tab_05.gif">
                                &nbsp;
                            </td>
                            <td width="14">
                                <img src="/Content/images/tab/tab_07.gif" width="14" height="30" />
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td style="margin: 4px 0px 4px 0px">
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td width="9" background="/Content/images/tab/tab_12.gif">
                                &nbsp;
                            </td>
                            <td width="8%">
                                列表名称:
                            </td>
                            <td width="8%">
                                <asp:DropDownList ID="drp_moviePlayList" runat="server">
                                </asp:DropDownList>
                            </td>
                            <td>
                                &nbsp;
                                <input id="btn_save" type="button" value="保存列表"><input type="button" value="添加广告"
                                    id="btn_add" /><div id="itemList">
                            </td>
                            <td>
                                &nbsp;
                            </td>
                            <td width="9" background="/Content/images/tab/tab_16.gif">
                                &nbsp;
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    <table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td width="9" background="/Content/images/tab/tab_12.gif">
                                &nbsp;
                            </td>
                            <td>
                                <table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
                                    <tr>
                                        <td style="text-align: center">
                                            <!-- End demo -->
                                            <asp:GridView ID="Grid_1" runat="server" AutoGenerateColumns="False" CellPadding="4"
                                                EnableModelValidation="True" ForeColor="#333333" GridLines="None" Width="100%"
                                                OnRowDataBound="Grid_1_RowDataBound" OnPageIndexChanging="Grid_1_PageIndexChanging"
                                                OnRowCancelingEdit="Grid_1_RowCancelingEdit" OnRowEditing="Grid_1_RowEditing"
                                                OnRowUpdating="Grid_1_RowUpdating" onrowdeleting="Grid_1_RowDeleting">
                                                <AlternatingRowStyle BackColor="White" />
                                                <RowStyle HorizontalAlign="Center" />
                                                <Columns>
                                                    <asp:BoundField DataField="PlayIndex" FooterText="排序编号" HeaderText="排序编号" />
                                                    <asp:BoundField DataField="AdName" ReadOnly="true" FooterText="广告名称" HeaderText="广告名称" />
                                                    <asp:TemplateField HeaderText="大图">
                                                        <ItemTemplate >
                                                            <a href="<%#Eval("Bigimgname")%>" class="tooltip" title="">
                                                                <%#Eval("Bigimgname") %>
                                                            </a>
                                                        </ItemTemplate>
                                                    </asp:TemplateField>
                                                    <asp:TemplateField HeaderText="小图">
                                                        <ItemTemplate>
                                                            <a href="<%#Eval("Smallimgname")%>" class="tooltip" title="">
                                                                <%#Eval("Bigimgname") %></a>
                                                        </ItemTemplate>
                                                    </asp:TemplateField>
                                                    <asp:BoundField DataField="CreateDate" ReadOnly="true" FooterText="上传日期" DataFormatString="{0:yyyy-MM-dd}"
                                                        HeaderText="上传日期" />
                                                    <asp:CommandField ShowEditButton="True" />
                                                    <asp:CommandField ShowDeleteButton="True" />
                                                </Columns>
                                                <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                                                <HeaderStyle BackColor="#cae1ac" Font-Bold="True" ForeColor="White" />
                                                <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
                                                <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
                                                <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
                                            </asp:GridView>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <td width="9" background="/Content/images/tab/tab_16.gif">
                                &nbsp;
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td height="29">
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td width="15" height="29">
                                <img src="/Content/images/tab/tab_20.gif" width="15" height="29" />
                            </td>
                            <td background="/Content/images/tab/tab_21.gif">
                                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                    <tr>
                                        <td width="25%" height="29" nowrap="nowrap">
                                        </td>
                                        <td width="75%" valign="top" class="STYLE1">
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <td width="14">
                                <img src="/Content/images/tab/tab_22.gif" width="14" height="29" />
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
